package com.coders.activities;

import org.cocos2d.nodes.CCDirector;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;

import com.coders.R;

public class ScoreCard extends Activity {
	TextView tvHighscore, tvPlayerName, tvScore;
	String TOTALSCORE = "score";
	String PLAYERNAME = "playername";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.scorecard);
		tvHighscore = (TextView) findViewById(R.id.tvHighscore);
		tvPlayerName = (TextView) findViewById(R.id.tvPlayerName);
		tvScore = (TextView) findViewById(R.id.tvScore);

		Typeface type = Typeface.createFromAsset(getAssets(), "Cookies.ttf");
		tvPlayerName.setTypeface(type);
		tvScore.setTypeface(type);
		try {
			SharedPreferences sharedPreference = CCDirector.sharedDirector()
					.getActivity().getSharedPreferences("sharedPreference", 0);
			String bp_totalscore = sharedPreference.getString(TOTALSCORE, null);
			String bp_playername = sharedPreference.getString(PLAYERNAME, null);
			tvPlayerName.setText(bp_playername);
			tvScore.setText(bp_totalscore);

		} catch (Exception e) {
			tvPlayerName.setText("NO Player");
			tvScore.setText("NO Score");
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		Intent intent = new Intent(ScoreCard.this, MainMenu.class);
		intent.putExtra("RESUME_YN", "N");

		ScoreCard.this.startActivity(intent);

		finish();
		return super.onKeyDown(keyCode, event);
	}
}
